﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
namespace hemsidan.Helpers
{
    public class FeedGenerator
    {
        private FeedGenerator()
        {
        }



        public static void WriteFeed(System.IO.Stream responseStream)
        {

            Rss.RssChannel channel = new Rss.RssChannel();

            DataTable blogs = Entities.Blog.GetRecent(10);

            foreach (DataRow r in blogs.Rows)
            {
                Rss.RssItem item = new Rss.RssItem();
                item.PubDate = (DateTime)r[3];
                item.Title = (string)r[1];
                item.Description = (string)r[2];


                channel.Items.Add(item);
            }

            channel.Title = Settings.SiteTitle;
            channel.Description = Settings.SiteTitle;
            channel.LastBuildDate = channel.Items.LatestPubDate();
            channel.Link = new Uri(Settings.URL);
            Rss.RssFeed feed = new Rss.RssFeed();
            feed.Channels.Add(channel);

            feed.Write(responseStream);
        }
    }
}